package com.yanqu.road.entity.activity.washe.eliminate;

import com.yanqu.road.entity.enums.washe.eWasheBlockType;
import com.yanqu.road.entity.enums.washe.eWasheColorType;
import com.yanqu.road.entity.enums.washe.eWasheDirectionType;

import java.util.ArrayList;
import java.util.List;

public class WasheBlock {

    private int x;
    private int y;
    private int color;

    private eWasheBlockType blockType = eWasheBlockType.Normal;
    private List<WasheBlockEffect> effectList = new ArrayList<>();
    private eWasheDirectionType direction = eWasheDirectionType.Up;

    // 消除后获得
    private int score;
    private int sp;

    // ============================================================


    public WasheBlock() {
    }

    public WasheBlock(int x, int y, int color) {
        this.x = x;
        this.y = y;
        this.color = color;
    }

    public static WasheBlock createFrame(int x, int y, eWasheBlockType frameType) {
        if (frameType.getBigType() != eWasheBlockType.BIG_TYPE_FRAME) {
            throw new RuntimeException("这个类型不是框");
        }

        WasheBlock block = new WasheBlock(x, y, eWasheColorType.None.getValue());
        block.setBlockType(frameType);
        return block;
    }

    public void addEffect(WasheBlockEffect effect) {
        if (effectList.stream().noneMatch(item -> item.getEffectType() == effect.getEffectType())) {
            this.effectList.add(effect);
        }
    }

    public WasheBlock clone() {
        WasheBlock block = new WasheBlock();

        block.setX(getX());
        block.setY(getY());
        block.setColor(getColor());

        block.setBlockType(getBlockType());
        List<WasheBlockEffect> effectList = new ArrayList<>();
        for (WasheBlockEffect tmpEffect : getEffectList()) {
            effectList.add(tmpEffect.clone());
        }
        block.setEffectList(effectList);
        block.setDirection(getDirection());

        block.setScore(getScore());
        block.setSp(getSp());
        return block;
    }

    // ============================================================

    public int getScore() {
        return score;
    }

    public void setScore(int score) {
        this.score = score;
    }

    public int getSp() {
        return sp;
    }

    public void setSp(int sp) {
        this.sp = sp;
    }

    public eWasheBlockType getBlockType() {
        return blockType;
    }

    public void setBlockType(eWasheBlockType blockType) {
        this.blockType = blockType;
    }

    public int getColor() {
        return color;
    }

    public void setColor(int color) {
        this.color = color;
    }

    public List<WasheBlockEffect> getEffectList() {
        return effectList;
    }

    public void setEffectList(List<WasheBlockEffect> effectList) {
        this.effectList = effectList;
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public eWasheDirectionType getDirection() {
        return direction;
    }

    public void setDirection(eWasheDirectionType direction) {
        this.direction = direction;
    }
}
